package o;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import androidx.annotation.NonNull;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.downloadengine.api.SplitTask;
import com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appmarket.service.thirdappdl.ThirdAppDownloadActivityProtocol;
import com.huawei.appmarket.service.thirdappdl.ThirdAppDownloadActivityProtocol.Request;
import com.huawei.hms.support.api.entity.hwid.HwIDConstant.ACTION;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import java.util.List;
import o.dge.d;
import o.dqw.c;
import o.ewm.n;

@SuppressLint({"InflateParams"})
public final class ejr {
    private static volatile ejr ˏ;
    SessionDownloadTask ॱ = null;

    private ejr() {
    }

    public static ejr ˏ() {
        if (ˏ == null) {
            ˏ = new ejr();
        }
        return ˏ;
    }

    public void ˏ(Context context, BaseDistCardBean baseDistCardBean) {
        if (baseDistCardBean != null && baseDistCardBean.ˑ() != null) {
            if (!dof.ॱ(baseDistCardBean.ˑ().ˏ()) && !dof.ॱ(baseDistCardBean.ˑ().ˊ()) && !dof.ॱ(baseDistCardBean.ˑ().ॱ())) {
                boolean ˏ = erw.ˏ(context, baseDistCardBean.ˑ().ˏ());
                int ˎ = erw.ˎ(context, baseDistCardBean.ˑ().ˏ());
                if (!ˏ || ˎ < baseDistCardBean.ˑ().ˎ()) {
                    cjo thirdAppDownloadActivityProtocol = new ThirdAppDownloadActivityProtocol();
                    Request request = new Request();
                    request.ॱ(baseDistCardBean.ˑ().ˏ());
                    request.ˏ(baseDistCardBean.ˑ().ˊ());
                    request.ˊ(baseDistCardBean.ˑ().ॱ());
                    request.ॱ(baseDistCardBean.ˑ().ˋ());
                    request.ˎ(baseDistCardBean.ˑ().ʻ());
                    request.ʻ(baseDistCardBean.ˑ().ʼ());
                    thirdAppDownloadActivityProtocol.ˊ(request);
                    cjk.ˎ().ˋ(context, new cjm("third_app_download.activity", thirdAppDownloadActivityProtocol));
                    if (Logger.ˎ()) {
                        Logger.ˏ("ThirdDownloadManager", "doing download process");
                        return;
                    }
                    return;
                }
                Uri parse = Uri.parse(baseDistCardBean.ˑ().ˊ());
                try {
                    context.startActivity(new Intent(ACTION.HWID_SCHEME_URL, parse));
                } catch (Exception e) {
                    evk.ˋ(context, context.getResources().getString(n.ˋᐧ), 0).ˋ();
                    Logger.ˋ("ThirdDownloadManager", "" + e.toString());
                }
                Logger.ˏ("ThirdDownloadManager", "url link:" + parse);
                if (baseDistCardBean.ˑ().ˋ() == 1) {
                    dgh.onEvent(new d(context, n.ꜟ).ˏ(baseDistCardBean.ˑ().ʻ() + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + baseDistCardBean.ˑ().ʼ()).ˋ());
                } else if (baseDistCardBean.ˑ().ˋ() == 2) {
                    dgh.onEvent(new d(context, n.ꓸ).ˏ(baseDistCardBean.ˑ().ʻ() + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + baseDistCardBean.ˑ().ʼ()).ˋ());
                }
            } else if (Logger.ˎ()) {
                Logger.ˏ("ThirdDownloadManager", "input para null");
            }
        }
    }

    public void ˎ(final ApkUpgradeInfo apkUpgradeInfo, final dkb.d dVar) {
        new dqw().ˏ(dqw.ˊ(apkUpgradeInfo.ᐝ(), apkUpgradeInfo.ॱʽ(), apkUpgradeInfo.ʿ() + ""), new c(this) {
            final /* synthetic */ ejr ˎ;

            public void ˋ(SessionDownloadTask sessionDownloadTask) {
                if (sessionDownloadTask != null) {
                    SplitTask splitTask;
                    this.ˎ.ॱ = sessionDownloadTask;
                    if (apkUpgradeInfo.ॱʽ() == 0) {
                        splitTask = new SplitTask();
                        splitTask.ˋ(apkUpgradeInfo.ˈ());
                        splitTask.ˊ(apkUpgradeInfo.ʾ());
                        splitTask.ˋ(apkUpgradeInfo.ʻॱ());
                        splitTask.ˊॱ(apkUpgradeInfo.ᐝ());
                        this.ˎ.ॱ.ˏ(splitTask);
                    }
                    this.ˎ.ॱ.ʽ(apkUpgradeInfo.ॱᐝ());
                    this.ˎ.ॱ.ॱॱ(apkUpgradeInfo.ˊ());
                    this.ˎ.ॱ.ʻ(apkUpgradeInfo.ʿ());
                    this.ˎ.ॱ.ˊ(apkUpgradeInfo.ˈ());
                    this.ˎ.ॱ.ʼ(apkUpgradeInfo.ᐝ());
                    this.ˎ.ॱ.ॱॱ(0);
                    this.ˎ.ॱ.ॱ(apkUpgradeInfo.ॱ());
                    this.ˎ.ॱ.ˏ(apkUpgradeInfo.ˊᐝ());
                    this.ˎ.ॱ.ॱ(apkUpgradeInfo.ˏˎ());
                    this.ˎ.ॱ.ॱˊ(apkUpgradeInfo.ॱʽ());
                    if (apkUpgradeInfo.ʼ() > 0) {
                        List ᐝˊ = this.ˎ.ॱ.ᐝˊ();
                        if (!CollectCheck.isEmpty(ᐝˊ)) {
                            splitTask = (SplitTask) ᐝˊ.get(0);
                            splitTask.ॱ(apkUpgradeInfo.ʼ());
                            splitTask.ˏ(apkUpgradeInfo.ॱॱ());
                            splitTask.ˎ(apkUpgradeInfo.ˈ());
                            splitTask.ˋ(apkUpgradeInfo.ʽॱ());
                        }
                        sessionDownloadTask.ˊ(apkUpgradeInfo.ʽॱ());
                    }
                }
                if (dVar != null) {
                    dVar.ˋ(this.ˎ.ॱ);
                }
            }

            public void ॱ() {
                Logger.e("ThirdDownloadManager", "getDownloadTask get bundle info fail.");
                if (dVar != null) {
                    dVar.ˋ(null);
                }
            }
        });
    }

    public void ˊ(ApkUpgradeInfo apkUpgradeInfo, Class<? extends cdt> cls, boolean z, int i, boolean z2, int i2) {
        if (apkUpgradeInfo == null) {
            Logger.e("ThirdDownloadManager", "doDownload upgradeInfo is null");
            return;
        }
        final int i3 = i;
        final int i4 = i2;
        final Class<? extends cdt> cls2 = cls;
        final boolean z3 = z2;
        ˎ(apkUpgradeInfo, new dkb.d(this) {
            final /* synthetic */ ejr ॱ;

            public void ˋ(SessionDownloadTask sessionDownloadTask) {
                if (sessionDownloadTask != null) {
                    this.ॱ.ॱ.ˊ(i3);
                    this.ॱ.ॱ.ˋ(new dvw());
                    this.ॱ.ॱ.ˋ(i4);
                    cdw.ˋ().ˋ(i4, cls2);
                    dvt.ˏ().ˊ(this.ॱ.ॱ, z3);
                }
            }
        });
    }

    public void ˎ() {
        if (this.ॱ != null) {
            dvt.ˏ().ॱ(this.ॱ.ʾ());
        }
    }

    public void ˊ() {
        this.ॱ = null;
    }

    public void ˋ(@NonNull SessionDownloadTask sessionDownloadTask, ejs o_ejs) {
        int ˏ = etn.ˏ(0);
        fhz ˋ = fho.ˏ().ˋ("PackageManager");
        if (ˋ != null) {
            cnw o_cnw = (cnw) ˋ.ॱ(cnw.class);
            if (o_cnw != null) {
                List<SplitTask> ᐝˊ = sessionDownloadTask.ᐝˊ();
                if (!CollectCheck.isEmpty(ᐝˊ)) {
                    cof.d ˏ2 = new cof.d().ˋ(sessionDownloadTask.ˊˊ()).ˏ(sessionDownloadTask.ॱᐝ()).ˊ(ˏ).ˏ(sessionDownloadTask).ˊ(coc.ˏ).ˏ(new ejp.d(o_ejs));
                    for (SplitTask splitTask : ᐝˊ) {
                        ˏ2.ॱ(splitTask.ॱˊ(), splitTask.ॱᐝ(), splitTask.ᐝॱ());
                    }
                    o_cnw.ˋ(ContentManager.getInstant().getContext(), ˏ2.ˎ());
                    return;
                }
                return;
            }
            Logger.e("ThirdDownloadManager", "can not found IPackageInstaller Api");
            return;
        }
        Logger.e("ThirdDownloadManager", "can not found PackageManager module");
    }
}
